package com.spzx.product.controller;

import com.github.pagehelper.PageHelper;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.SkuQuery;
import com.spzx.product.api.domain.vo.ProductSkuVo;
import com.spzx.product.service.IProductSkuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 商品sku 前端控制器
 * </p>
 *
 * @author lee
 * @since 2024-07-15
 */
@Tag(name = "商品sku管理")
@RestController
@RequestMapping("/productSku")
public class ProductSkuController extends BaseController {

    @Autowired
    private IProductSkuService productSkuService;

    @Operation(summary = "获取前20的畅销商品")
    @GetMapping("/getTopSale")
    @InnerAuth
    public R<List<ProductSku>> getTopSale(){
        return R.ok(productSkuService.getTopSale());
    }

    @InnerAuth
    @Operation(summary = "查询商品列表")
    @GetMapping("/getProductSkuList/{pageNum}/{pageSize}")
    public TableDataInfo getProductList(
            @Parameter(name = "pageNum", description = "当前页码", required = true)
            @PathVariable Integer pageNum,
            @Parameter(name = "pageSize", description = "页大小", required = true)
            @PathVariable Integer pageSize,
            SkuQuery skuQuery){
        PageHelper.startPage(pageNum,pageSize);
        List<ProductSkuVo> productList = productSkuService.getProductList(skuQuery);
        return getDataTable(productList);
    }

}
